import React, {Component} from 'react';
import PubSub from 'pubsub-js';
import './Top.scss'

class Top extends Component {
    state = {
        kwyword: ''
    }

    componentDidMount() {
        setTimeout(()=>{
            this.getData()//初始化获取数据
        },500)
    }

    //发布搜索事件
    getData = () => {
        PubSub.publish('搜索', this.state.kwyword)
    }

    render() {
        return (
            <div className={"search-input"}>
                <div className={"input"}>
                    <input value={this.state.kwyword} onChange={e => this.setState({kwyword: e.target.value})}/>
                </div>
                <div className={"button"}>
                    <button onClick={this.getData}>搜索</button>
                </div>
            </div>
        );
    }
}

export default Top;